package o;

import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import org.json.JSONException;
import org.json.JSONObject;

public class eop {
    private static boolean ˋ = false;

    public static void ˎ(UserSession userSession) {
        if (userSession != null) {
            try {
                String toJson = userSession.toJson();
                eor.ˏ().ˊ("us_version", 1);
                eor.ˏ().ˏ("us_value", toJson);
                Logger.ˎ("UserSessionCacheUtil", "cache UserInfo");
            } catch (IllegalAccessException e) {
                Logger.e("UserSessionCacheUtil", "cache user session failed IllegalAccessException");
            }
        }
    }

    public static void ˏ() {
        if (!ˋ) {
            eua ˏ = eua.ˏ();
            boolean z = false;
            if (ˏ.ॱॱ("cacheServiceToken")) {
                ˏ.ʼ("cacheServiceToken");
                ˏ.ʼ("cacheAuthAccount");
                ˏ.ʼ("cacheDeviceType");
                z = true;
            }
            if (ˏ.ॱॱ("preEncryptStr_cacheServiceToken")) {
                ˏ.ʼ("preEncryptStr_cacheServiceToken");
                ˏ.ʼ("preEncryptStr_cacheAuthAccount");
                ˏ.ʼ("preEncryptStr_cacheDeviceType");
                z = true;
            }
            if (z) {
                ˏ.ˑ();
                Logger.ˎ("UserSessionCacheUtil", "Delete old version's cache.");
            }
            eor ˏ2 = eor.ˏ();
            if (ˏ2.ॱॱ("us_value")) {
                int ॱ = ˏ2.ॱ("us_version", -1);
                if (ॱ != 1) {
                    Logger.ˎ("UserSessionCacheUtil", "cache version mismatch:" + ॱ + "-" + 1);
                    ॱ();
                    return;
                }
                Object ˊ = ˏ2.ˊ("us_value", "");
                if (TextUtils.isEmpty(ˊ)) {
                    Logger.e("UserSessionCacheUtil", "cache value is empty.");
                    ॱ();
                } else {
                    try {
                        JSONObject jSONObject = new JSONObject(ˊ);
                        UserSession userSession = new UserSession();
                        userSession.fromJson(jSONObject);
                        UserSession.getInstance().loadCache(userSession);
                    } catch (JSONException e) {
                        Logger.e("UserSessionCacheUtil", "cacheUserSessionStr error JSONException");
                        ॱ();
                    } catch (IllegalArgumentException e2) {
                        Logger.e("UserSessionCacheUtil", "cacheUserSessionStr error IllegalArgumentException");
                        ॱ();
                    } catch (IllegalAccessException e3) {
                        Logger.e("UserSessionCacheUtil", "cacheUserSessionStr error IllegalAccessException");
                        ॱ();
                    } catch (InstantiationException e4) {
                        Logger.e("UserSessionCacheUtil", "cacheUserSessionStr error InstantiationException");
                        ॱ();
                    } catch (ClassNotFoundException e5) {
                        Logger.e("UserSessionCacheUtil", "cacheUserSessionStr error ClassNotFoundException");
                        ॱ();
                    }
                }
            } else {
                Logger.ˎ("UserSessionCacheUtil", "NO user cache.");
            }
            ˋ = true;
        }
    }

    public static void ॱ() {
        eor.ˏ().ʼ("us_value");
        Logger.ˎ("UserSessionCacheUtil", "Remove user cache.");
    }
}
